package com.aegean.MonitorExamSYS.center.dao.impl;

import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.FlushMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.aegean.MonitorExamSYS.center.component.ConductionInfoForExaminee;
import com.aegean.MonitorExamSYS.center.component.PositionInfoForExaminee;
import com.aegean.MonitorExamSYS.center.component.SelectCity;
import com.aegean.MonitorExamSYS.center.component.SelectConductionInfo;
import com.aegean.MonitorExamSYS.center.component.SelectExamInfo;
import com.aegean.MonitorExamSYS.center.component.SelectExaminee;
import com.aegean.MonitorExamSYS.center.component.SelectPosition;
import com.aegean.MonitorExamSYS.center.dao.CenterDao;
import com.aegean.MonitorExamSYS.center.tools.TypeConvert;
import com.aegean.MonitorExamSYS.tools.MyTools;
import com.aegean.MonitorExaxSYS.model.BigType;
import com.aegean.MonitorExaxSYS.model.CenterValue;
import com.aegean.MonitorExaxSYS.model.ConductionValue;
import com.aegean.MonitorExaxSYS.model.ExamInfo;
import com.aegean.MonitorExaxSYS.model.ExamPosition;
import com.aegean.MonitorExaxSYS.model.ExamPositionQualification;
import com.aegean.MonitorExaxSYS.model.ExamineeQualification;
import com.aegean.MonitorExaxSYS.model.MessageBox;
import com.aegean.MonitorExaxSYS.model.MonitorQualification;
import com.aegean.MonitorExaxSYS.model.MonitorValue;
import com.aegean.MonitorExaxSYS.model.PositionQualification;
import com.aegean.MonitorExaxSYS.model.SmallType;

@Repository
@Transactional
public class CenterDaoImpl implements CenterDao {
	@Resource
	SessionFactory factory;

	@Override
	public void insertService(CenterValue service) {
		// TODO Auto-generated method stub
		Session session = factory.getCurrentSession();
		try {
			if (service != null) {
				session.save(service);
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

	public CenterValue searchService(CenterValue service) {
		Session session = null;
		CenterValue one;
		try {
			session = factory.getCurrentSession();
			if (service != null) {
				Criteria c = session.createCriteria(CenterValue.class);
				c.add(Restrictions.eq("user_Login", service.getUser_Login()));
				c.add(Restrictions.eq("user_Password",
						service.getUser_Password()));
				one = (CenterValue) c.uniqueResult();
				if (one == null) {
					return null;
				}
				return one;
			}
			return null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public int searchBigTypeCount() {
		Session session = null;
		try {
			session = factory.getCurrentSession();
			Criteria cr = session.createCriteria(BigType.class);
			cr.add(Restrictions.eq("big_State", 1));
			cr.setCacheable(true);
			int count = cr.list().size();
			return count;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	@Override
	public List<BigType> searchPartBigTypes(int start, int limit) {
		Session session = null;
		List<BigType> bigtypes = null;
		try {
			session = factory.getCurrentSession();
			Criteria cr = session.createCriteria(BigType.class);
			cr.add(Restrictions.eq("big_State", 1));
			cr.setFirstResult(start);
			cr.setMaxResults(limit);
			cr.setCacheable(true);
			bigtypes = (List<BigType>) cr.list();
			return bigtypes;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public boolean searchBigType(String name) {
		Session session = null;
		try {
			session = factory.getCurrentSession();
			Criteria cr = session.createCriteria(BigType.class);
			cr.add(Restrictions.eq("big_Name", name));
			cr.add(Restrictions.eq("big_State", 1));
			cr.setCacheable(true);
			BigType o = (BigType) cr.uniqueResult();
			if (o == null) {
				return false;
			} else {
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public List<BigType> searchBigList() {
		// TODO Auto-generated method stub
		Session session = null;
		try {
			session = factory.getCurrentSession();
			Criteria cr = session.createCriteria(BigType.class);
			cr.setCacheable(true);
			return cr.list();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public boolean searchSmallType(String name) {
		Session session = null;
		try {
			session = factory.getCurrentSession();
			Criteria cr = session.createCriteria(SmallType.class);
			cr.add(Restrictions.eq("small_Name", name));
			cr.add(Restrictions.eq("small_State", 1));
			cr.setCacheable(true);
			SmallType o = (SmallType) cr.uniqueResult();
			if (o == null) {
				return false;
			} else {
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public boolean addBigType(BigType one) {
		Session session = null;
		try {
			session = factory.getCurrentSession();
			session.save(one);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public boolean addSmallType(SmallType one, int bigType_Id) {
		Session session = null;
		try {
			session = factory.getCurrentSession();
			Query q = session
					.createSQLQuery("insert into smalltype(SMALL_NAME,SMALL_STATE,SMALL_DATE,SMALL_BIG) values(?,?,?,?)");
			q.setString(0, one.getSmall_Name());
			q.setInteger(1, one.getSmall_State());
			q.setDate(2, one.getSmall_Date());
			q.setInteger(3, bigType_Id);
			q.executeUpdate();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public boolean editBigType(BigType one) {
		Session session;
		BigType big;
		try {
			session = factory.getCurrentSession();
			Criteria cr = session.createCriteria(BigType.class);
			big = (BigType) cr.add(
					Restrictions.eq("big_Name", one.getBig_Name()))
					.uniqueResult();
			big.setBig_Date(one.getBig_Date());
			big.setBig_State(one.getBig_State());
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public boolean editSmallType(SmallType one) {
		Session session = null;
		SmallType small;
		try {
			session = factory.getCurrentSession();
			Criteria cr = session.createCriteria(SmallType.class);
			small = (SmallType) cr.add(
					Restrictions.eq("small_Name", one.getSmall_Name()))
					.uniqueResult();
			small.setSmall_Date(one.getSmall_Date());
			small.setSmall_State(one.getSmall_State());
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public boolean deleteBigType(String[] big_Name) {
		Session session = null;
		try {
			session = factory.getCurrentSession();
			for (int i = 0; i < big_Name.length; i++) {
				BigType big = new BigType();
				Criteria cr = session.createCriteria(BigType.class);
				big = (BigType) cr
						.add(Restrictions.eq("big_Name", big_Name[i]))
						.uniqueResult();
				session.delete(big);
				session.flush();
				session.clear();
			}
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public int searchSmallTypeCount(String bigName) {
		Session session = null;
		BigType one;
		try {
			session = factory.getCurrentSession();
			if (bigName == null || bigName.trim().length() == 0) {
				Criteria cr = session.createCriteria(SmallType.class);
				cr.add(Restrictions.eq("small_State", 1));
				cr.setCacheable(true);
				return cr.list().size();
			} else {
				Criteria cr = session.createCriteria(BigType.class);
				cr.add(Restrictions.eq("big_State", 1));
				cr.add(Restrictions.eq("big_Name", bigName));
				cr.setCacheable(true);
				one = (BigType) cr.uniqueResult();
				Criteria c = session.createCriteria(SmallType.class);
				cr.add(Restrictions.eq("small_State", 1));
				c.add(Restrictions.eq("small_Big", one));
				c.setCacheable(true);
				return c.list().size();
			}
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	@Override
	public List<SmallType> searchPartSmallTypes(String bigName, int start,
			int limit) {
		Session session = null;
		BigType one;
		try {
			session = factory.getCurrentSession();
			if (bigName == null || bigName.trim().length() == 0) {
				Criteria cr = session.createCriteria(SmallType.class);
				cr.add(Restrictions.eq("small_State", 1));
				cr.setFirstResult(start);
				cr.setMaxResults(limit);
				cr.setCacheable(true);
				return cr.list();
			} else {
				Criteria cr = session.createCriteria(BigType.class);
				cr.add(Restrictions.eq("big_State", 1));
				cr.add(Restrictions.eq("big_Name", bigName));
				cr.setCacheable(true);
				one = (BigType) cr.uniqueResult();
				Criteria c = session.createCriteria(SmallType.class);
				c.add(Restrictions.eq("small_Big", one));
				cr.add(Restrictions.eq("small_State", 1));
				c.setFirstResult(start);
				c.setMaxResults(limit);
				c.setCacheable(true);
				return c.list();
			}
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public boolean deleteSmallType(int[] big_Ids) {
		Session session = null;
		try {
			session = factory.getCurrentSession();
			for (int i = 0; i < big_Ids.length; i++) {
				SmallType one = (SmallType) session.load(SmallType.class,
						big_Ids[i]);
				session.delete(one);
				session.flush();
				session.clear();
			}
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public boolean searchExamValue(String name) {
		Session session = null;
		try {
			session = factory.getCurrentSession();
			Criteria cr = session.createCriteria(ExamInfo.class);
			cr.add(Restrictions.eq("Exam_Name", name));
			cr.setCacheable(true);
			ExamInfo o = (ExamInfo) cr.uniqueResult();
			if (o == null) {
				return false;
			} else {
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public boolean addExamValue(ExamInfo one, int Small_Id) {
		Session session = null;
		SmallType small;
		try {
			session = factory.getCurrentSession();
			small = (SmallType) session.load(SmallType.class, Small_Id);
			one.setExamInfo_Type(small);
			session.save(one);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public int searchExamValueCount(int small_Id) {
		Session session = null;
		try {
			session = factory.getCurrentSession();
			Query q = session.createSQLQuery(
					"select * from examinfo where EXAMINFO_TYPE=?").addEntity(
					ExamInfo.class);
			q.setInteger(0, small_Id);
			q.setCacheable(true);
			return q.list().size();
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
	}

	@Override
	public List<ExamInfo> searchPartExamValues(int small_Id, int start,
			int limit) {
		Session session = null;
		try {
			session = factory.getCurrentSession();
			Query q = session.createSQLQuery(
					"select * from examinfo where EXAMINFO_TYPE=?").addEntity(
					ExamInfo.class);
			q.setInteger(0, small_Id);
			q.setFirstResult(start);
			q.setMaxResults(limit);

			return (List<ExamInfo>) q.list();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public boolean editExamValue(ExamInfo one, File photo) {
		Session session = null;
		ExamInfo exam;
		try {
			session = factory.getCurrentSession();
			exam = (ExamInfo) session
					.load(ExamInfo.class, one.getExamInfo_Id());
			if (photo == null) {
				exam.setExamInfo_Money(one.getExamInfo_Money());
				exam.setExamInfo_StartTime(one.getExamInfo_StartTime());
				exam.setExamInfo_EndTime(one.getExamInfo_EndTime());
				exam.setExamInfo_Comments(one.getExamInfo_Comments());
			} else {
				exam.setExamInfo_Money(one.getExamInfo_Money());
				exam.setExamInfo_StartTime(one.getExamInfo_StartTime());
				exam.setExamInfo_EndTime(one.getExamInfo_EndTime());
				exam.setExamInfo_Comments(one.getExamInfo_Comments());
				exam.setExamInfo_Photo(one.getExamInfo_Photo());
			}
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public boolean deleteExamValue(int[] Exam_Ids) {
		Session session = null;
		try {
			session = factory.getCurrentSession();
			for (int i = 0; i < Exam_Ids.length; i++) {
				ExamInfo one = (ExamInfo) session.load(ExamInfo.class,
						Exam_Ids[i]);
				session.delete(one);
				session.flush();
				session.clear();
			}
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public List<ExamInfo> searchLeastExams() {
		// TODO Auto-generated method stub
		Session session = null;
		try {
			session = factory.getCurrentSession();
			Criteria cr = session.createCriteria(ExamInfo.class);
			cr.addOrder(Order.desc("examInfo_CreateTime"));
			cr.setFirstResult(0);
			cr.setMaxResults(5);
			cr.setCacheable(true);
			return cr.list();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public List<SelectExamInfo> showExanList(int small_Id, int state)
			throws Exception {
		// TODO Auto-generated method stub
		ResultSet rs = null;
		PreparedStatement ps = null;
		Connection cn = null;
		Session session;
		List<SelectExamInfo> ls = new ArrayList<SelectExamInfo>();
		try {
			// TODO Auto-generated method stub
			switch (state) {
			case 0:// 通过选择来显示信息
				session = factory.getCurrentSession();
				String sql = "select exam.examinfo_id,exam.examInfo_StartTime,exam.examinfo_name, count(distinct epq.exampq_id),exam.examInfo_EndTime from examinfo as exam left join exampositionqualification as epq on exam.examinfo_id=epq.exampq_exam where  exam.examinfo_state=0 and exam.examinfo_type=? group by exam.examinfo_id";
				cn = session.connection();
				ps = cn.prepareStatement(sql);
				ps.setInt(1, small_Id);
				rs = ps.executeQuery();
				String ids = "";
				while (rs.next()) {
					SelectExamInfo one = new SelectExamInfo();
					one.setL_id(rs.getInt(1));
					one.setL_time(MyTools.toTime(rs.getString(2)));
					one.setL_name(rs.getString(3));
					one.setConduction_Count(rs.getInt(4));
					one.setL_etime(MyTools.toTime(rs.getString(5)));
					ls.add(one);
					ids += one.getL_id() + ",";
				}
				if (ids.endsWith(",")) {
					int len = ids.length();
					ids = ids.substring(0, len - 1).trim();
				}
				if (ids.isEmpty()) {
					return null;
				}
				Query q = session
						.createQuery("select examinee_PQ.examPQ_Exam.examInfo_Id,count(examinee_PQ.examPQ_Exam) from ExamineeQualification where examinee_PQ.examPQ_Exam.examInfo_Type.small_Id="
								+ small_Id
								+ " group by examinee_PQ.examPQ_Exam "
								+ " having examinee_PQ.examPQ_Exam in ("
								+ ids
								+ ") ");
				q.setCacheable(true);
				List idlist = q.list();
				for (SelectExamInfo object : ls) {
					for (int i = 0; i < idlist.size(); i++) {
						Object[] obj = (Object[]) idlist.get(i);
						if (object.getL_id() == Integer.parseInt(obj[0]
								.toString())) {
							object.setL_person_Count(Integer.parseInt(obj[1]
									.toString()));
						}
					}
				}
				break;
			case 1:
				session = factory.getCurrentSession();
				String sql1 = "select exam.examinfo_id,exam.examInfo_StartTime,exam.examinfo_name, count(distinct epq.exampq_id),exam.examInfo_EndTime from examinfo as exam left join exampositionqualification as epq on exam.examinfo_id=epq.exampq_exam   where exam.examinfo_state=0 and DATE_SUB(CURDATE(), INTERVAL 1 WEEK) <= date(exam.examinfo_createtime) group by exam.examinfo_id";
				cn = session.connection();
				ps = cn.prepareStatement(sql1);
				rs = ps.executeQuery();
				String ids1 = "";
				while (rs.next()) {
					SelectExamInfo one = new SelectExamInfo();
					one.setL_id(rs.getInt(1));
					one.setL_time(MyTools.toTime(rs.getString(2)));
					one.setL_name(rs.getString(3));
					one.setConduction_Count(rs.getInt(4));
					one.setL_etime(MyTools.toTime(rs.getString(5)));
					ls.add(one);
					ids1 += one.getL_id() + ",";
				}
				if (ids1.endsWith(",")) {
					int len = ids1.length();
					ids1 = ids1.substring(0, len - 1).trim();
				}
				if (ids1.isEmpty()) {
					return null;
				}
				Query q1 = session
						.createQuery("select examinee_PQ.examPQ_Exam.examInfo_Id,count(examinee_PQ.examPQ_Exam) from ExamineeQualification "
								+ " group by examinee_PQ.examPQ_Exam "
								+ " having examinee_PQ.examPQ_Exam in ("
								+ ids1
								+ ") ");
				q1.setCacheable(true);
				List idlist1 = q1.list();
				for (SelectExamInfo object : ls) {
					for (int i = 0; i < idlist1.size(); i++) {
						Object[] obj = (Object[]) idlist1.get(i);
						if (object.getL_id() == Integer.parseInt(obj[0]
								.toString())) {
							object.setL_person_Count(Integer.parseInt(obj[1]
									.toString()));
						}
					}
				}
				break;
			case 2:
				session = factory.getCurrentSession();
				String sql2 = "select exam.examinfo_id,exam.examInfo_StartTime,exam.examinfo_name, count(distinct epq.exampq_id),exam.examInfo_EndTime from examinfo as exam left join exampositionqualification as epq on exam.examinfo_id=epq.exampq_exam   where exam.examinfo_state=0 and DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(exam.examinfo_createtime) group by exam.examinfo_id";
				cn = session.connection();
				ps = cn.prepareStatement(sql2);
				rs = ps.executeQuery();
				String ids2 = "";
				while (rs.next()) {
					SelectExamInfo one = new SelectExamInfo();
					one.setL_id(rs.getInt(1));
					one.setL_time(MyTools.toTime(rs.getString(2)));
					one.setL_name(rs.getString(3));
					one.setConduction_Count(rs.getInt(4));
					one.setL_etime(MyTools.toTime(rs.getString(5)));
					ls.add(one);
					ids2 += one.getL_id() + ",";
				}
				if (ids2.endsWith(",")) {
					int len = ids2.length();
					ids2 = ids2.substring(0, len - 1).trim();
				}
				if (ids2.isEmpty()) {
					return null;
				}
				Query q2 = session
						.createQuery("select examinee_PQ.examPQ_Exam.examInfo_Id,count(examinee_PQ.examPQ_Exam) from ExamineeQualification "
								+ " group by examinee_PQ.examPQ_Exam "
								+ " having examinee_PQ.examPQ_Exam in ("
								+ ids2
								+ ") ");
				q2.setCacheable(true);
				List idlist2 = q2.list();
				for (SelectExamInfo object : ls) {
					for (int i = 0; i < idlist2.size(); i++) {
						Object[] obj = (Object[]) idlist2.get(i);
						if (object.getL_id() == Integer.parseInt(obj[0]
								.toString())) {
							object.setL_person_Count(Integer.parseInt(obj[1]
									.toString()));
							break;
						}
					}
				}
				break;
			}
			return ls;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		} finally {
			rs.close();
			ps.close();
			cn.close();
		}
	}

	@Override
	public List<SelectConductionInfo> showConductionList(int exam_Id,
			int state, Date startTime, Date endTime) throws Exception {
		// TODO Auto-generated method stub
		Session session;
		ResultSet rs = null;
		PreparedStatement ps = null;
		Connection cn = null;
		String ids = "";
		List<SelectConductionInfo> ls = new ArrayList<SelectConductionInfo>();
		try {
			switch (state) {
			case 0:
				session = factory.getCurrentSession();
				Query q1 = session
						.createQuery("select examPQ_Conduction.conduction_Id,examPQ_Conduction.conduction_Name,examPQ_Conduction.conduction_Address.place_City,examPQ_Conduction.conduction_Address.place_Region from ExamPositionQualification where examPQ_Exam.examInfo_Id=:exam_Id");
				q1.setInteger("exam_Id", exam_Id);
				q1.setCacheable(true);
				List l1 = q1.list();
				for (int i = 0; i < l1.size(); i++) {
					Object[] obj = (Object[]) l1.get(i);
					SelectConductionInfo one = new SelectConductionInfo();
					one.setId(Integer.parseInt(obj[0].toString()));
					one.setName(obj[1].toString());
					one.setCity(obj[2].toString());
					one.setRegion(obj[3].toString());
					one.setNo(i + 1);
					ls.add(one);
					ids += Integer.parseInt(obj[0].toString()) + ",";
				}
				if (ids.endsWith(",")) {
					int len = ids.length();
					ids = ids.substring(0, len - 1).trim();
				}
				Query q2 = session
						.createQuery("select examinee_PQ.examPQ_Conduction.conduction_Id,count(examinee_PQ.examPQ_Id) from ExamineeQualification "
								+ "where"
								+ " examinee_PQ.examPQ_Exam.examInfo_Id=:exam_Id"
								+ " group by examinee_PQ.examPQ_Id "
								+ " having examinee_PQ.examPQ_Conduction.conduction_Id in ("
								+ ids + ")");
				q2.setInteger("exam_Id", exam_Id);
				q2.setCacheable(true);
				List l2 = q2.list();
				for (SelectConductionInfo con : ls) {
					for (int i = 0; i < l2.size(); i++) {
						Object[] obj = (Object[]) l2.get(i);
						if (con.getId() == Integer.parseInt(obj[0].toString()
								.trim())) {
							con.setPersonCount(Integer.parseInt(obj[1]
									.toString().trim()));
							break;
						}
					}
				}
				cn = session.connection();
				String sql = "select con.conduction_id,sum(ep.examposition_personcount)from examposition as ep,conductionvalue as con where ep.examposition_unit=con.conduction_id and con.conduction_id in ("
						+ ids
						+ ") and ep.examposition_id not in (select pq.pq_ep from positionqualification as pq,exampositionqualification as eq,examinfo as exam where pq.pq_epq=eq.exampq_id and eq.exampq_exam=exam.examinfo_id and (exam.examinfo_starttime  between date_format(?,'%Y-%m-%d %H:%i:%s') and date_format(?,'%Y-%m-%d %H:%i:%s') || exam.examinfo_endtime  between date_format(?,'%Y-%m-%d %H:%i:%s') and date_format(?,'%Y-%m-%d %H:%i:%s')))group by con.conduction_id";
				ps = cn.prepareStatement(sql);
				ps.setString(1, MyTools.toDateString(startTime));
				ps.setString(2, MyTools.toDateString(endTime));
				ps.setString(3, MyTools.toDateString(startTime));
				ps.setString(4, MyTools.toDateString(endTime));
				rs = ps.executeQuery();
				while (rs.next()) {
					for (SelectConductionInfo con : ls) {
						if (con.getId() == rs.getInt(1)) {
							con.setIncludeCount(rs.getInt(2));
							break;
						}
					}
				}
				break;
			default:
				break;
			}
			return ls;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			rs.close();
			ps.close();
			cn.close();
		}
	}

	@Override
	public List<ExamPosition> showPositionList(int unit_Id, Date startTime,
			Date endTime) {
		// TODO Auto-generated method stub
		Session session;
		List<PositionQualification> pqs;
		try {
			session = factory.getCurrentSession();

			String sql = "from PositionQualification where "
					+ "(pq_Epq.examPQ_Exam.examInfo_StartTime between :startTime and :endTime  "
					+ "or pq_Epq.examPQ_Exam.examInfo_EndTime between :startTime and :endTime) "
					+ " and pq_Ep.examPosition_Unit.conduction_Id=:unit_Id";
			Query q = session.createQuery(sql);
			q.setString("startTime", MyTools.toDateString2(startTime));
			q.setString("endTime", MyTools.toDateString2(endTime));
			q.setInteger("unit_Id", unit_Id);
			q.setCacheable(true);
			pqs = q.list();
			String ids = "";
			for (PositionQualification one : pqs) {
				ids += one.getPq_Id() + ",";
			}
			if (ids.endsWith(",")) {
				int len = ids.length();
				ids = ids.substring(0, len - 1).trim();
			}
			String sql2 = "select * from examposition as ep where ep.examposition_unit=:unit_Id";
			if (pqs.size() == 0) {
			} else {
				sql2 += " and ep.examposition_id not in (select pq_ep from positionqualification where pq_id in ("
						+ ids + "))";
			}
			Query q2 = session.createSQLQuery(sql2).addEntity(
					ExamPosition.class);
			q2.setInteger("unit_Id", unit_Id);
			q2.setCacheable(true);
			return q2.list();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public List<ExamPosition> showPositionLists(Object[] objects,
			Date startTime, Date endTime) {
		// TODO Auto-generated method stub
		Session session;
		List<PositionQualification> pqs;
		String id = "";// 定义考点Id集合
		try {
			for (Object object : objects) {
				id += object.toString().trim() + ",";
			}
			if (id.endsWith(",")) {
				int len = id.length();
				id = id.substring(0, len - 1).trim();
			}
			session = factory.getCurrentSession();
			String sql = "from PositionQualification where "
					+ "(pq_Epq.examPQ_Exam.examInfo_StartTime between :startTime and :endTime  "
					+ "or pq_Epq.examPQ_Exam.examInfo_EndTime between :startTime and :endTime) "
					+ " and pq_Ep.examPosition_Unit.conduction_Id in (" + id
					+ ")";
			Query q = session.createQuery(sql);
			q.setString("startTime", MyTools.toDateString2(startTime));
			q.setString("endTime", MyTools.toDateString2(endTime));
			q.setCacheable(true);
			pqs = q.list();
			String ids = "";
			for (PositionQualification one : pqs) {
				ids += one.getPq_Id() + ",";
			}
			if (ids.endsWith(",")) {
				int len = ids.length();
				ids = ids.substring(0, len - 1).trim();
			}
			String sql2 = "select * from examposition as ep where ep.examposition_unit in ("
					+ id + ")";
			if (ids.length() != 0) {
				sql2 += " and ep.examposition_id not in (select pq_ep from positionqualification where pq_id in ("
						+ ids + "))";
			}
			Query q2 = session.createSQLQuery(sql2).addEntity(
					ExamPosition.class);
			q2.setCacheable(true);
			return q2.list();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public boolean confirmArrageForCP(Map<Integer, List<Integer>> cp,
			Map<Integer, Integer> cpc, int exam_Id, Date exam_StartTime) {
		Session session;
		try {
			session = factory.getCurrentSession();
			Object[] conduction_Ids = cp.keySet().toArray();
			ExamInfo exam = (ExamInfo) session.load(ExamInfo.class, exam_Id);
			for (int j = 0; j < conduction_Ids.length; j++) {
				int conduction_Id = Integer.parseInt(conduction_Ids[j]
						.toString().trim());
				Query q = session
						.createQuery("from ExamPositionQualification where examPQ_Conduction.conduction_Id=:con_Id and examPQ_Exam.examInfo_Id=:exam_Id");
				q.setInteger("con_Id", conduction_Id);
				q.setInteger("exam_Id", exam_Id);
				q.setCacheable(true);
				ExamPositionQualification epq = (ExamPositionQualification) q
						.uniqueResult();
				for (Integer i : cp.get(conduction_Id)) {// 考场信息Id
					ExamPosition ep = (ExamPosition) session.load(
							ExamPosition.class, i);
					PositionQualification pq = new PositionQualification();
					pq.setPq_Ep(ep);// 对应考场
					pq.setPq_Epq(epq);// 对应考点资格
					pq.setPq_State(1);// 设定考场资格的初始状态，1代表已经设定，0代表已经结束
					session.save(pq);
					pq.setPq_Identity(TypeConvert.toDateString(exam_StartTime)// 考试开始时间
							.trim() + exam_Id// 考试项目ID
							+ epq.getExamPQ_Id()// 考点资格Id
							+ i// 考场Id
							+ pq.getPq_Id());// 设定考场资格Identity:考试开始时间+考试项目Id+考点资格Id+考场Id+考场资格Id
				}
				epq.setExamPQ_PersonCount(cpc.get(conduction_Id));
				epq.setExamPQ_State(2);// 2为考点资格已经设定完成或者理解为已经同意该考点申办考试
				if (j % 20 == 0) {
					session.flush();
					session.clear();
				}
			}
			exam.setExamInfo_State(1);// 1代表考点分配已经完成
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public List<ExamInfo> showExanListForMonitorAndExaminee(int small_Id,
			int state, int status) throws Exception {
		// TODO Auto-generated method stub
		Session session;
		try {
			session = factory.getCurrentSession();
			switch (state) {
			case 0:
				Query q = session
						.createQuery("from ExamInfo where examInfo_State="
								+ status
								+ " and examInfo_Type.small_Id=:small_Id");
				q.setInteger("small_Id", small_Id);
				q.setCacheable(true);
				return q.list();
			default:
				Query q1 = session
						.createQuery("from ExamInfo where examInfo_State="
								+ status);
				q1.setCacheable(true);
				return q1.list();
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public List<SelectPosition> showPositionListForMonitor(int exam_Id) {
		// TODO Auto-generated method stub
		Session session;
		List<SelectPosition> positions = new ArrayList<SelectPosition>();
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			session = factory.getCurrentSession();
			String sql = "SELECT pq.PQ_ID as id,ep.EXAMPOSITION_NAME as name,pq.PQ_IDENTITY as identity,unit.CONDUCTION_ID,unit.CONDUCTION_NAME as unit_Name FROM positionqualification AS pq,exampositionqualification AS epq,examinfo AS exam,examposition AS ep,conductionvalue AS unit "
					+ "WHERE epq.EXAMPQ_EXAM=exam.EXAMINFO_ID AND pq.PQ_EPQ=epq.EXAMPQ_ID AND pq.PQ_EP=ep.EXAMPOSITION_ID AND ep.EXAMPOSITION_UNIT=unit.CONDUCTION_ID AND exam.EXAMINFO_ID="
					+ exam_Id;
			conn = session.connection();
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				SelectPosition position = new SelectPosition();
				position.setId(rs.getInt(1));
				position.setName(rs.getString(2));
				position.setIdentity(rs.getString(3));
				position.setUnit_Id(rs.getInt(4));
				position.setUnit_Name(rs.getString(5));
				positions.add(position);
			}
			return positions;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		} finally {
			try {
				rs.close();
				ps.close();
				conn.close();
			} catch (SQLException e2) {
				// TODO: handle exception
				e2.printStackTrace();
			}
		}
	}

	@Override
	public List<MonitorValue> showMonitorsListForMonitor(int unit_Id,
			Date startTime, Date endTime) {
		// TODO Auto-generated method stub
		Session session;
		List<MonitorQualification> mqs;
		try {
			session = factory.getCurrentSession();
			String hql = "from MonitorQualification where (monitor_Position.pq_Epq.examPQ_Exam.examInfo_StartTime between :startTime and :endTime or monitor_Position.pq_Epq.examPQ_Exam.examInfo_EndTime between :startTime and :endTime) and monitor_User.monitor_Unit.conduction_Id=:unit_Id ";
			Query q = session.createQuery(hql);
			q.setString("startTime", MyTools.toDateString2(startTime));
			q.setString("endTime", MyTools.toDateString2(endTime));
			q.setInteger("unit_Id", unit_Id);
			q.setCacheable(true);
			mqs = q.list();
			String ids = "";
			for (MonitorQualification one : mqs) {
				ids += one.getMonitorQ_Id() + ",";
			}
			if (ids.endsWith(",")) {
				int len = ids.length();
				ids = ids.substring(0, len - 1).trim();
			}
			String sql2 = "SELECT us.*,m.* FROM monitorvalue AS m,uservalue AS us,bigtype AS big WHERE us.USER_ID=m.USER_ID AND m.MONITOR_BIG=big.BIG_ID AND m.MONITOR_STATE=1 AND m.MONITOR_UNIT="
					+ unit_Id;
			if (mqs.size() == 0) {

			} else {
				sql2 += " AND m.USER_ID NOT IN (SELECT mq.MONITOR_USER FROM monitorqualification AS mq WHERE mq.MONITORQ_ID IN ("
						+ ids + ")) order by m.monitor_big";
			}
			Query q2 = session.createSQLQuery(sql2).addEntity("monitor",
					MonitorValue.class);
			q2.setCacheable(true);
			return q2.list();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public boolean confirmArrangeMonitors(int exam_Id, Date startTime,
			Map<Integer, List<Integer>> maps) {
		// TODO Auto-generated method stub
		Session session;
		try {
			session = factory.getCurrentSession();
			Set<Integer> keys = maps.keySet();
			Iterator<Integer> it = keys.iterator();
			int count = 0;
			while (it.hasNext()) {
				Integer pq_Id = it.next();// 考场资格ID
				List<Integer> monitor_Ids = maps.get(pq_Id);
				for (Integer integer : monitor_Ids) {
					MonitorValue monitor = (MonitorValue) session.load(
							MonitorValue.class, integer);
					PositionQualification pq = (PositionQualification) session
							.load(PositionQualification.class, pq_Id);
					MonitorQualification mq = new MonitorQualification();
					mq.setMonitor_User(monitor);
					mq.setMonitor_Position(pq);
					/* 监考人员资格号:考试时间+考试项目Id+考场资格Id+监考人员id */
					mq.setMonitorQ_Identity(TypeConvert.toDateString(startTime)
							+ exam_Id + pq_Id + integer);
					session.save(mq);
				}
				count++;
				if (count % 50 == 0) {
					session.flush();
					session.clear();
				}
			}
			ExamInfo exam = (ExamInfo) session.load(ExamInfo.class, exam_Id);// 考试状态设置为2代表监考人员安排已经工程
			exam.setExamInfo_State(2);//
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public int searchBigId(int exam_Id) {
		// TODO Auto-generated method stub
		Session session;
		try {
			String sql = "SELECT big.* FROM  bigtype AS big,smalltype AS small,examinfo AS exam WHERE exam.EXAMINFO_TYPE=small.SMALL_ID AND small.SMALL_BIG=big.BIG_ID AND exam.EXAMINFO_ID="
					+ exam_Id;
			session = factory.getCurrentSession();
			Query q = session.createSQLQuery(sql).addEntity(BigType.class);
			q.setCacheable(true);
			BigType big = (BigType) q.uniqueResult();
			return big.getBig_Id();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return 0;
		}
	}

	@Override
	public List<ConductionInfoForExaminee> showConductionListForExaminee(
			int exam_Id) {
		// TODO Auto-generated method stub
		Session session;
		List<ConductionInfoForExaminee> conductions = new ArrayList<ConductionInfoForExaminee>();
		try {
			session = factory.getCurrentSession();
			String hql = "select con.conduction_Id,con.conduction_Name,con.conduction_Address.place_City,con.conduction_Address.place_Region,epq.examPQ_PersonCount,epq.examPQ_Id,con.conduction_Address.place_H,con.conduction_Address.place_V from ConductionValue as con,ExamPositionQualification as epq where epq.examPQ_Conduction=con and epq.examPQ_State=2 and examPQ_PersonCount!=0 and  epq.examPQ_Exam.examInfo_Id=:exam_Id";
			Query q = session.createQuery(hql);
			q.setInteger("exam_Id", exam_Id);
			q.setCacheable(true);
			List l = q.list();
			for (int i = 0; i < l.size(); i++) {
				Object[] obj = (Object[]) l.get(i);
				ConductionInfoForExaminee con = new ConductionInfoForExaminee();
				con.setId(Integer.parseInt(obj[0].toString().trim()));
				con.setName(obj[1].toString().trim());
				con.setCity(obj[2].toString().trim());
				con.setRegion(obj[3].toString().trim());
				con.setPersonCount(Integer.parseInt(obj[4].toString().trim()));
				con.setEpq_Id(Integer.parseInt(obj[5].toString().trim()));
				con.setPlace_H(Float.parseFloat((obj[6].toString().trim())));
				con.setPlace_V(Float.parseFloat((obj[7].toString().trim())));
				conductions.add(con);
			}
			return conductions;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public List<PositionInfoForExaminee> showPositionListForExaminee(
			int exam_Id, int con_Id) {
		// TODO Auto-generated method stub
		Session session;
		List<PositionInfoForExaminee> positions = new ArrayList<PositionInfoForExaminee>();
		try {
			session = factory.getCurrentSession();
			String hql = "select ep.examPosition_PersonCount,pq.pq_Id from ExamPosition as ep,PositionQualification as pq where ep.examPosition_Unit.conduction_Id=:unit_Id and pq.pq_Ep=ep and pq.pq_Epq.examPQ_Exam.examInfo_Id=:exam_Id and pq.pq_State=1";
			Query q = session.createQuery(hql);
			q.setInteger("unit_Id", con_Id);
			q.setInteger("exam_Id", exam_Id);
			q.setCacheable(true);
			List l = q.list();
			for (int i = 0; i < l.size(); i++) {
				Object[] obj = (Object[]) l.get(i);
				PositionInfoForExaminee position = new PositionInfoForExaminee();
				position.setExamPosition_PersonCount(Integer.parseInt(obj[0]
						.toString().trim()));
				position.setExamPQ_Id(Integer
						.parseInt(obj[1].toString().trim()));
				positions.add(position);
			}
			return positions;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public List<SelectExaminee> showExamineesList(int exam_Id) {
		// TODO Auto-generated method stub
		Session session;
		List<SelectExaminee> examinees = new ArrayList<SelectExaminee>();
		try {
			session = factory.getCurrentSession();
			String hql = "select e.user_Id,e.user_RealName,e.examineeValue_Address.place_City,e.examineeValue_Address.place_Region,eq.examinee_Id,eq.examinee_PQ.examPQ_Id,e.examineeValue_Address.place_H,e.examineeValue_Address.place_V from ExamineeQualification as eq,ExamineeValue as e where eq.examinee_User=e and eq.examinee_PQ.examPQ_Exam.examInfo_Id=:exam_Id and eq.examinee_State=0 order by eq.examinee_Id";
			Query q = session.createQuery(hql);
			q.setInteger("exam_Id", exam_Id);
			q.setCacheable(true);
			List l = q.list();
			for (int i = 0; i < l.size(); i++) {
				Object[] obj = (Object[]) l.get(i);
				SelectExaminee con = new SelectExaminee();
				con.setUser_Id(Integer.parseInt(obj[0].toString().trim()));
				con.setUser_Name(obj[1].toString().trim());
				con.setCity(obj[2].toString().trim());
				con.setRegion(obj[3].toString().trim());
				con.setUser_Identity_Id(Integer.parseInt(obj[4].toString()
						.trim()));
				con.setExam_Pq((Integer.parseInt(obj[5].toString().trim())));
				con.setPlace_H(Float.parseFloat((obj[6].toString().trim())));
				con.setPlace_V(Float.parseFloat((obj[7].toString().trim())));
				con.setExam_Id(exam_Id);
				examinees.add(con);
			}
			return examinees;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public boolean confirmExaminees(
			Map<Integer, Map<Integer, List<SelectExaminee>>> maps, Date time,
			int exam_Id) {
		// TODO Auto-generated method stub
		Session session;
		try {
			session = factory.getCurrentSession();
			Set<Integer> unit_Ids = maps.keySet();// 考点资格集合
			for (Integer unit_Id : unit_Ids) {
				Map<Integer, List<SelectExaminee>> valueMap = maps.get(unit_Id);
				ExamPositionQualification epq = (ExamPositionQualification) session
						.load(ExamPositionQualification.class, unit_Id);// 考点资格实体类
				Set<Integer> p_Ids = valueMap.keySet();// 考场集合
				for (Integer p_Id : p_Ids) {
					List<SelectExaminee> examinees = valueMap.get(p_Id);
					PositionQualification pq = (PositionQualification) session
							.load(PositionQualification.class, p_Id);// 考场资格实体类
					for (int e = 1; e <= examinees.size(); e++) {
						SelectExaminee examinee = examinees.get(e - 1);
						ExamineeQualification eq = (ExamineeQualification) session
								.load(ExamineeQualification.class,
										examinee.getUser_Identity_Id());
						eq.setExaminee_PQ(epq);// 考点资格更改
						eq.setExamineePQ(pq);// 考场资格设置
						eq.setExaminee_State(1);// 状态1说明已经分配，0代表没有分配
						eq.setExaminee_Identity(TypeConvert.toDateString(time)
								+ unit_Id + p_Id + e);// 考生资格Id:考试时间+考点资格Id+考场资格Id+该考场考生的序列个数
					}
					pq.setPq_State(2);// 代表该考场资格已经分配
					session.flush();
					session.clear();
				}
			}
			ExamInfo exam = (ExamInfo) session.load(ExamInfo.class, exam_Id);
			exam.setExamInfo_State(3);// 考生资格已经安排完毕，即所有资格都已经安排完毕
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public List<SelectCity> showCitys() {
		Session session;
		List<SelectCity> citys = new ArrayList<SelectCity>();
		try {
			String hql = "select distinct conduction_Address.place_City from ConductionValue ";
			session = factory.getCurrentSession();
			Query q = session.createQuery(hql);
			q.setCacheable(true);
			List l = q.list();
			for (int i = 0; i < l.size(); i++) {
				String obj = (String) l.get(i);
				SelectCity one = new SelectCity();
				one.setCity_Id(i + 1);
				System.out.println(obj);
				one.setCity_Name(obj.trim());
				citys.add(one);
			}
			return citys;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public List<ConductionValue> showConductions(String city_Name, int start,
			int limit) {
		// TODO Auto-generated method stub
		Session session;
		try {
			session = factory.getCurrentSession();
			Criteria c = session.createCriteria(ConductionValue.class);
			c.add(Restrictions.like("conduction_Address.place_City", "%"
					+ city_Name + "%"));
			c.setFirstResult(start);
			c.setMaxResults(limit);
			c.setCacheable(true);
			return c.list();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public boolean writeMessage(int conduction_Id, String theme, String contents) {
		// TODO Auto-generated method stub
		Session session;
		try {
			session = factory.getCurrentSession();
			MessageBox box = new MessageBox();
			box.setMessage_Date(new Date());
			box.setMessage_State(2);// 相对于校方是收信
			box.setMessage_Theme(theme);
			box.setMessage_Contents(contents);
			box.setMessage_IdBefore(0);// 没有上一节邮箱
			ConductionValue one = (ConductionValue) session.load(
					ConductionValue.class, conduction_Id);
			box.setMessage_From(one);
			session.save(box);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public List<MessageBox> showMessages(int state, int status,
			int conduction_Id, int start, int limit) {
		// TODO Auto-generated method stub
		Connection cn;
		PreparedStatement ps;
		ResultSet rs;
		List<MessageBox> messages = new ArrayList<MessageBox>();
		Session session;
		String hql = null;
		try {
			session = factory.getCurrentSession();
			if (state == 1) {// 收件箱
				hql = "select m.*,c.conduction_name as place_Name,b.message_theme as message_BeforeTheme from messagebox m left join messagebox b on m.message_idbefore=b.message_id ,conductionvalue as c where m.message_from=c.conduction_id and m.message_State=1  order by m.message_Date desc limit "
						+ start + "," + limit + "";
			} else if (state == 2) {// 发件箱
				hql = "select m.*,c.conduction_name as place_Name,b.message_theme as message_BeforeTheme from messagebox m left join messagebox b on m.message_idbefore=b.message_id ,conductionvalue as c where m.message_from=c.conduction_id and m.message_State=2  order by m.message_Date desc limit "
						+ start + "," + limit + "";
			} else if (state == 3) {// 指定高校
				hql = "select m.*,c.conduction_name as place_Name,b.message_theme as message_BeforeTheme from messagebox m left join messagebox b on m.message_idbefore=b.message_id ,conductionvalue as c where m.message_from=c.conduction_id and m.message_From.conduction_Id="
						+ conduction_Id
						+ " order by m.message_Date desc limit "
						+ start
						+ ","
						+ limit + "";
			} else if (state == 4) {
				hql = "select m.*,c.conduction_name as place_Name,b.message_theme as message_BeforeTheme from messagebox m left join messagebox b on m.message_idbefore=b.message_id ,conductionvalue as c where m.message_from=c.conduction_id and DATE_SUB(CURDATE(), INTERVAL 1 WEEK) <= date(m.message_Date)  order by m.message_Date desc limit "
						+ start + "," + limit + "";
			} else if (state == 5) {
				hql = "select m.*,c.conduction_name as place_Name,b.message_theme as message_BeforeTheme from messagebox m left join messagebox b on m.message_idbefore=b.message_id ,conductionvalue as c where m.message_from=c.conduction_id  order by m.message_Date desc limit "
						+ start + "," + limit + "";
			}
			cn = session.connection();
			ps = cn.prepareStatement(hql);
			rs = ps.executeQuery();
			while (rs.next()) {
				MessageBox one = new MessageBox();
				one.setMessage_Id(rs.getInt(1));
				one.setMessage_Theme(rs.getString(2));
				one.setMessage_Contents(rs.getString(3));
				one.setMessage_Date(rs.getDate(4));
				one.setMessage_IdBefore(rs.getInt(5));
				ConductionValue c = new ConductionValue();
				c.setConduction_Id(rs.getInt(7));
				one.setMessage_From(c);
				one.setMessage_State(rs.getInt(6));
				one.setPlace_Name(rs.getString(8));
				if (rs.getString(9) == null || rs.getString(9).equals("")) {
					one.setMessage_BeforeTheme("无");
				} else {
					one.setMessage_BeforeTheme(rs.getString(9));
				}
				messages.add(one);
			}
			return messages;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean replyMessage(int conduction_Id, String theme,
			String contents, int beforeId) {
		Session session;
		try {
			session = factory.getCurrentSession();
			MessageBox box = new MessageBox();
			box.setMessage_Date(new Date());
			box.setMessage_State(2);// 相对于校方是收信
			box.setMessage_Theme(theme);
			box.setMessage_Contents(contents);
			box.setMessage_IdBefore(beforeId);
			ConductionValue one = (ConductionValue) session.load(
					ConductionValue.class, conduction_Id);
			box.setMessage_From(one);
			session.save(box);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}
	}
}
